package com.zpark.se.thread;

import java.time.LocalTime;

/**
 * @PackageName: com.zpark.se.thread
 * @ClassName: Demo11
 * @Description:
 * @author: RZS
 * @date: 2024/11/29  14:51
 */
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        // 创建线程
        // Thread t = new MyThr();
        Thread t = new MyT();
        // 将当前线程设置为守护线程
        t.setDaemon(true);
        // 启动线程
        t.start();

        // main线程休眠1秒
        Thread.sleep(1000);
    }
}

class MyThr extends Thread{
    @Override
    public void run() {
        while (true) {
            System.out.println(LocalTime.now());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class MyT extends Thread{
    @Override
    public void run() {
        // 创建MyThr线程
        MyThr t = new MyThr();
        // 启动线程
        t.start();
        // 中断t线程
        t.interrupt();
    }
}
